//
//  PersonalNetTool.m
//  IntegralDog
//
//  Created by User on 16/3/16.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "PersonalNetTool.h"
#import "AFNetworking.h"
#import "Macro.h"

@implementation PersonalNetTool
//个人信息
+ (void)getPersonalcomplationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    [manager POST:PERSON_MESSAGE_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        NSLog(@"huoqugerenxinxi%@",responseObject);
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}
//修改个人信息
+ (void)UpdateUserWithNickname:(NSString *)nickname complationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token",nickname,@"nickname", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:UPDARE_MESSAGE_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        NSLog(@"chenggong  %@  ",responseObject);
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

//修改头像信息
+ (void)UpdateHeaderWithLogo:(NSString *)logo filepath:(NSData *)filepath complationBlock:(void(^)(NSDictionary *dic))complation{
    //http://172.16.9.28:8080/integration_dog/app/updateUserLogo?uid=1&token=076a3b66-a186-4e1a-b9a9-b2e0ea5f6247&logo=logo
    NSString *urlStr  = [NSString stringWithFormat:@"%@?uid=%d&token=%@&logo=%@",UPDARE_LOGO_URL,UID,TOKEN,logo];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *filename = [NSString stringWithFormat:@"%@.png",logo];
    [manager POST:urlStr parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:filepath name:@"image" fileName:filename mimeType:@"image/png"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
       NSLog(@"%@",str);
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"eerr:%@",error);
    }];
}

//退出
+ (void)loginOutcomplationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
     manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    [manager POST:LOGIN_OUT_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

//排行榜
+ (void)getRankingWithType:(int)Type complationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token",@(Type),@"type", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:GET_RANKING_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        NSLog(@"chenggong  %@  ",responseObject);
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

//应用列表
+ (void)getProductListWithpage:(int)page  rows:(int)rows complationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token",@(page),@"page",@(rows),@"rows", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer=[AFJSONRequestSerializer serializer];

    
    [manager POST:PRODUCT_LIST_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        //NSLog(@"product  %@  ",responseObject);
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}
//应用详情
+ (void)getProductDetailsWithpid:(int)pid  complationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token",@(pid),@"pid", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:PRODUCT_DETAILS_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

//下载记录
+ (void)getdownloadRecordWithpage:(int)page rows:(int)rows date:(NSString *)date complationBlock:(void(^)(NSDictionary *dic))complation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@(UID),@"uid",TOKEN,@"token",@(page),@"page",@(rows),@"rows",date,@"date", nil];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:DOWNLOAD_RECORD_URL parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        __block NSDictionary *dic = responseObject;
        if (complation) {
            complation(dic);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
    
}
@end
